package com.zg.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Component;


import javax.annotation.Resource;

@Component
@Slf4j
public class MqttBrokerMsgSave {
    @Resource
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 保存相关消息
     * @param data
     */
    public void saveMsg(String data) {
        long start = System.currentTimeMillis();
        rocketMQTemplate.asyncSend("lot-msg-save", data, new SendCallback() {
            @Override
            public void onSuccess(SendResult sendResult) {
                log.info("发送保存消息成功，返回结果：{}",sendResult);
            }

            @Override
            public void onException(Throwable throwable) {
                System.out.println(throwable);
            }
        });
        long end = System.currentTimeMillis();
        log.info("线程：{}，执行保存消息：{},耗时：{}",Thread.currentThread().getName(),data,end-start);
    }

    /**
     * 推送订阅主题数量
     */
}
